package start.gui;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.net.URL;

import javax.swing.*;

import start.StrongBoxClient;

public class ImagePanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ImageIcon img;
	protected StrongBoxClient sbc;
	
	public static Font LABELFONT = new Font(Font.SANS_SERIF,Font.PLAIN,25);

	public ImagePanel(String imagePath,StrongBoxClient client) {
		super();
		img = createIcon(imagePath);
		sbc = client;
	}
	

	public void paintComponent(Graphics g){
		super.paintComponents(g);
		this.setSize(new Dimension(img.getIconWidth(),img.getIconHeight()));
		Dimension panelSize=getSize();
		int width=img.getIconWidth();
		int height=img.getIconHeight();
		for(int i=0;i<panelSize.height;i+=height)
			for(int j=0;j<panelSize.width;j+=width)
				img.paintIcon(this, g,j,i);

	}
	
	public StrongBoxClient getClient(){
		return sbc;
	}
	
	protected void showPopup(String messT,String text,int type){
		JOptionPane.showMessageDialog(this, 
				text,
				messT,
				type
		);
	}
	
	protected ImageIcon createIcon(String path){
		ImageIcon icon = null;
		URL url = ImagePanel.class.getResource(path);
		if(url != null)
			icon = new ImageIcon(url);
		else
			System.err.println("Could not find requested image");
		return icon;
	}
}